package saeildamil.ch18.communication;

import javax.swing.JOptionPane;

public class CalcPiThread extends Thread {
	SharedArea sharedArea;

	public CalcPiThread(SharedArea sharedArea) {
		this.sharedArea = sharedArea;
	}
	@Override
	public void run() {
		double total = 0.0;
		for(int cnt =1; cnt < 1000000000; cnt +=2){
			if(cnt / 2 %2 ==0)
				total += 1.0/cnt;
			else
				total -= 1.0/cnt;
		}
		sharedArea.result = total * 4;
		sharedArea.isReady = true;
		JOptionPane.showMessageDialog(null, "Pi 계산 완료");
		synchronized (sharedArea){
			JOptionPane.showMessageDialog(null, "대기중인 printthread 전송");
			sharedArea.notifyAll();//shraedArea에서 wait()에 의해 대기하고 있는 스레드에게 신호보냄
		}
	}
	
}
